using System;
using System.Collections.Generic;
using ilgolosone.Shared.IoC;
using StructureMap;

namespace ilgolosone.DependencyResolver.SM
{
    public class StructureMapDependencyResolver : IDependencyResolver
    {
        private readonly IContainer _container;

        public StructureMapDependencyResolver(IContainer container)
        {
            if (container == null) throw new ArgumentNullException("container");
            
            _container = container;
        }

        public TService Resolve<TService>()
        {
            return _container.GetInstance<TService>();
        }

        public TService Resolve<TService>(string key)
        {
            return _container.GetInstance<TService>(key);
        }

        public IEnumerable<TService> ResolveAll<TService>()
        {
            return _container.GetAllInstances<TService>();
        }

        public void Dispose()
        {
            // StructureMap non ha bisogno di disposing...
            return;
        }
    }
}